﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BaHuan.BusinessLayer;
using BaHuan.Common;
using BaHuan.Entities;

namespace BaHuan
{
    public partial class FrmTimKiemVatLieu : Form
    {
        private HangHoaManagement hanghoaMgt = new HangHoaManagement();
        private DonGiaNguyenVatLieuManagement dongianguyenvatlieuMgt = new DonGiaNguyenVatLieuManagement();
        public event FormCloseTimKiemVatLieu formclosetimkiemvatlieu = null;

        private string ChuoiTimKiem = null;

        public FrmTimKiemVatLieu()
        {
            InitializeComponent();
        }

        public FrmTimKiemVatLieu(string sTimKiem)
        {
            InitializeComponent();
            this.ChuoiTimKiem = sTimKiem;
        }

        private void FrmTimKiemVatLieu_Load(object sender, EventArgs e)
        {
            ResultObj result = new ResultObj();            
            result = hanghoaMgt.GetAllHangHoa();

            List<HangHoa> lstHangHoa = (from c in (List<HangHoa>)result.Result
                                        where c.ChuoiTimKiem.Contains(ChuoiTimKiem) &&
                                        c.IsDelete==0
                                        select c).ToList();

            dgvTimKiem.AutoGenerateColumns = false;
            if (lstHangHoa.Count > 0)
                dgvTimKiem.DataSource = lstHangHoa;
            else
            {
                MessageBox.Show("Không có dữ liệu phù hợp");
                this.Close();
            }            
        }

        private void dgvTimKiem_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (formclosetimkiemvatlieu != null)
                {
                    formclosetimkiemvatlieu(Convert.ToInt32(dgvTimKiem.CurrentRow.Cells[0].Value), dgvTimKiem.CurrentRow.Cells[1].Value.ToString(), false);
                }
                this.Close();
            }        
        }
    }
}
